The SetData
method is used to update the contents of the GpuBuffer<T>
with new data. This method allows you to specify a span of data to be copied into the buffer starting at a specified offset.
The SetData
method is used to update the contents of the GpuBuffer<T>
with new data. This method allows you to specify a span of data to be copied into the buffer starting at a specified offset.
To use the SetData
method, you need to provide a System.Span<T>
containing the data you want to set, and an integer elementOffset
which specifies the starting position in the buffer where the data should be copied.
Ensure that the data type T
is blittable, as required by the GpuBuffer<T>
class.
// Example of using SetData method GpuBuffer<float> gpuBuffer = new GpuBuffer<float>(); // Create a span of data to set Span<float> data = stackalloc float[] { 1.0f, 2.0f, 3.0f }; // Set data in the GPU buffer starting at offset 0 gpuBuffer.SetData(data, 0);